package com.atguigu.atcrowdfunding.listener;

import com.atguigu.atcrowdfunding.util.Const;
import com.sun.org.slf4j.internal.Logger;
import com.sun.org.slf4j.internal.LoggerFactory;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/*
* 监听application对象创建和销毁
* */
public class SystemUplnitListener implements ServletContextListener {
    Logger log= LoggerFactory.getLogger(SystemUplnitListener.class);
    //当application创建时执行初始化
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        ServletContext application = sce.getServletContext();
        String contextPath= application.getContextPath();
        log.debug("当前应用上下文路径:{}",contextPath);
        application.setAttribute(Const.PATH, contextPath);

    }
//当application销毁时执行销毁方法
    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        log.debug("当前应用application销毁时对象被销毁");
    }
}
